﻿Public Class SuperCommanButton
    Inherits Windows.Forms.Button

    Dim intResize As Single = 96 / 100
    Dim blnRestored As Boolean = False

    Public Sub New()
        Me.FlatStyle = Windows.Forms.FlatStyle.Flat
        Me.FlatAppearance.MouseOverBackColor = Drawing.Color.Transparent
        Me.FlatAppearance.MouseDownBackColor = Drawing.Color.Transparent
        Me.FlatAppearance.BorderSize = 0
        Me.BackgroundImageLayout = Windows.Forms.ImageLayout.Stretch
        Me.Size = New Drawing.Size(110, 32)
        Me.ForeColor = Drawing.Color.White
        Me.BackgroundImage = My.Resources.imgMouseLeave
    End Sub

    Private Sub SuperCommanButton_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        Me.BackgroundImage = My.Resources.imgMouseClick
        Me.Width = Me.Width * intResize
        Me.Height = Me.Height * intResize
        Me.Left = Me.Left + (Me.Width / intResize - Me.Width) / 2
        Me.Top = Me.Top + (Me.Height / intResize - Me.Height) / 2
        blnRestored = False
    End Sub

    Private Sub SuperCommanButton_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseHover
        Me.BackgroundImage = My.Resources.imgMouseHover
        System.Windows.Forms.Application.DoEvents
        Me.ForeColor = Color.Black
        System.Windows.Forms.Application.DoEvents()
    End Sub

    Private Sub SuperCommanButton_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseLeave
        Me.BackgroundImage = My.Resources.imgMouseLeave
        System.Windows.Forms.Application.DoEvents()
        Me.ForeColor = Color.White
        System.Windows.Forms.Application.DoEvents()
    End Sub

    Private Sub SuperCommanButton_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
        If Not blnRestored Then Restore()
    End Sub

    Private Sub SuperCommanButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
        If Not blnRestored Then Restore()
    End Sub

    Private Sub Restore()
        Me.Width = Me.Width / intResize
        Me.Height = Me.Height / intResize
        Me.Left = Me.Left - (Me.Width / intResize - Me.Width) / 2
        Me.Top = Me.Top - (Me.Height / intResize - Me.Height) / 2
        blnRestored = True
    End Sub

End Class